package com.aaa.tars.controller;

import com.aaa.tars.entity.Dot;
import com.aaa.tars.service.DotService;
import com.aaa.tars.util.Page;
import com.aaa.tars.util.Result;
import com.aaa.tars.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @FileName: DotController
 * @Description:
 * @Author: 李宗盛
 * @CreateTime: 2025/9/11 8:45
 * @Version: 17
 */
@RestController
@RequestMapping("/dot")
public class DotController {
    @Autowired
    private DotService dotService;
    
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<Dot> page){
        return ResultUtil.success(dotService.queryByPage(page));
    }

    @PostMapping("frontQueryByPage")
    public Result frontQueryByPage(@RequestBody Page<Dot> page){
        return ResultUtil.success(dotService.frontQueryByPage(page));
    }

    @GetMapping("queryById")
    public Result queryById(Integer dotId){
        return ResultUtil.success(dotService.queryById(dotId));
    }
    // 在DotController中添加
    @GetMapping("/queryByScenicId")
    public Result queryDotsByScenicId(@RequestParam Integer scenicId) {
        try {
            List<Dot> dots = dotService.queryByScenicId(scenicId);
            return ResultUtil.success(dots);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("查询景点失败: " + e.getMessage());
        }
    }
    @PostMapping("add")
    public Result add(@RequestBody Dot dot){
        return ResultUtil.success(dotService.add(dot));
    }
    
    @PostMapping("update")
    public Result update(@RequestBody Dot dot){
        return ResultUtil.success(dotService.update(dot));
    }
    
    @DeleteMapping("deleteById")
    public Result deleteById(Integer dotId){
        return ResultUtil.success(dotService.deleteById(dotId));
    }
    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestParam("file") MultipartFile file) {
        return dotService.uploadImage(file);
    }
}